package com.redis.common.component.exception;

import org.springframework.http.HttpStatus;

/**
 * @description: 未经授权的异常
 * @Author C_Y_J
 * @create 2022/1/12 9:52
 **/
public class UnauthorizedException extends CustomOAuth2Exception {

    public UnauthorizedException(String msg, Throwable t) {
        super(msg);
    }

    @Override
    public String getOAuth2ErrorCode() {
        return "unauthorized";
    }

    @Override
    public int getHttpErrorCode() {
        return HttpStatus.UNAUTHORIZED.value();
    }

    /**
     * @description: 认为服务挂了
     * @Author C_Y_J
     * @create 2022/1/12 9:52
     **/
    public static class ServerErrorException extends CustomOAuth2Exception {

        public ServerErrorException(String msg, Throwable t) {
            super(msg);
        }

        @Override
        public String getOAuth2ErrorCode() {
            return "server_error";
        }

        @Override
        public int getHttpErrorCode() {
            return HttpStatus.INTERNAL_SERVER_ERROR.value();
        }
    }

    /**
     * @description: 禁止访问
     * @Author C_Y_J
     * @create 2022/1/12 9:52
     **/
    public static class ForbiddenException extends CustomOAuth2Exception {

        public ForbiddenException(String msg, Throwable t) {
            super(msg, t);
        }

        @Override
        public String getOAuth2ErrorCode() {
            return "access_denied";
        }

        @Override
        public int getHttpErrorCode() {
            return HttpStatus.FORBIDDEN.value();
        }

    }

    /**
     * @description: grant_type不支持
     * @Author C_Y_J
     * @create 2022/1/12 9:52
     **/
    public static class InvalidException extends CustomOAuth2Exception {

        public InvalidException(String msg, Throwable t) {
            super(msg);
        }

        @Override
        public String getOAuth2ErrorCode() {
            return "invalid_exception";
        }

        @Override
        public int getHttpErrorCode() {
            return 426;
        }
    }

    /**
     * @description:
     * @Author C_Y_J
     * @create 2022/1/12 9:52
     **/
    public static class MethodNotAllowedException extends CustomOAuth2Exception {

        public MethodNotAllowedException(String msg, Throwable t) {
            super(msg);
        }

        @Override
        public String getOAuth2ErrorCode() {
            return "method_not_allowed";
        }

        @Override
        public int getHttpErrorCode() {
            return HttpStatus.METHOD_NOT_ALLOWED.value();
        }
    }

    /**
     * @description:
     * @Author C_Y_J
     * @create 2022/1/12 9:52
     **/
    public static class TokenInvalidException extends CustomOAuth2Exception {

        public TokenInvalidException(String msg, Throwable t) {
            super(msg);
        }

        @Override
        public String getOAuth2ErrorCode() {
            return "invalid_token";
        }

        @Override
        public int getHttpErrorCode() {
            return HttpStatus.FAILED_DEPENDENCY.value();
        }
    }

}